/**
 * Simple regex experiment to create an automatic emoticons by Taufik Nurrohman and modified by aiizahhblog-team, and thanks to indo.mt5 for the smilies
 * Visit: http://aiizahh.blogspot.com
 * Update: 23 April 2013
 */

$(function() {

	// Append an emoticon bar before comment-form
	if (putEmoAbove) {
		$(putEmoAbove).before('<div class="emoWrap"> dad deff depressed greedy dontcare order shake slap smoke spoiled support tired angry1 angry2 cheer cry4 drunk happy haii hmmm huhhh khekhe omg peace2 pleased wat2 wind</div>');
	}
	function emo(emo, imgRep, emoKey) {
		$(emoRange).each(function() {
			$(this).html($(this).html().replace(/<br ?\/?>(:|;|=|\^)/ig, "<br> $1").replace(emo, " <img src='" + imgRep + "' class='emo delayLoad' alt='" + emoKey + "' />"));
		});
	}
	emo(/\s:senyum:/g, "http://2.bp.blogspot.com/-XhXJiYquXN4/UqO0BEC-vfI/AAAAAAAADW8/VgqnAJCG7PY/s1600/senyum.png", ":senyum:");
	emo(/\s:sedih:/g, "http://1.bp.blogspot.com/-vSrpKRLdllI/UqO0AwpCLeI/AAAAAAAADWs/oUyAVXsn0FE/s1600/sedih.png", ":sedih:");
	emo(/\s:kedip:/g, "http://3.bp.blogspot.com/-w2O9chjEu0E/UqOz8i7bh9I/AAAAAAAADVk/AnDL2vlohp4/s1600/kedip.png", ":kedip:");
	emo(/\s:ketawa:/g, "http://1.bp.blogspot.com/-iDJvgvMi6-k/UqOz9c7O4_I/AAAAAAAADV0/iLVZ7SD6LnE/s1600/ketawa.png", ":ketawa:");
	emo(/\s:mikir:/g, "http://2.bp.blogspot.com/-1tIt0Dpzy-0/UqOz_cvUvHI/AAAAAAAADWM/LfuKlMcbzcU/s1600/mikir.png", ":mikir:");
	emo(/\s:malu:/ig, "http://1.bp.blogspot.com/-iN2NxbpgYyc/UqOz9s2-DeI/AAAAAAAADV4/p06zlq0a0xw/s1600/malu.png", ":malu:");
	emo(/\s:ngejek:/ig, "http://4.bp.blogspot.com/-5ZPJ-4FDCrg/UqO0AEHaMbI/AAAAAAAADWY/jdYLImXpda4/s1600/ngejek.png", ":ngejek:");
	emo(/\s:cium:/g, "http://3.bp.blogspot.com/-pvOC9RNQ77I/UqOz8agksNI/AAAAAAAADVc/lsgOjdUZ1Dw/s1600/cium.png", ":cium:");
	emo(/\s:ngantuk:/g, "http://4.bp.blogspot.com/-tf5ZkrFo-SY/UqOz_q-8CJI/AAAAAAAADWQ/TKFYwIUaQo8/s1600/ngantuk.png", ":ngantuk:");
	emo(/\s:shock:/g, "http://3.bp.blogspot.com/-7DhXwAN95d8/UqO0BckAH-I/AAAAAAAADXA/YdHzCHm0U3Q/s1600/shock.png", ":shock:");
	emo(/\s:marah:/g, "http://2.bp.blogspot.com/-llmUC6JCDQU/UqOz-kNw2fI/AAAAAAAADWE/nABux1t0H4I/s1600/marah.png", ":marah:");
	emo(/\s:nangis:/g, "http://1.bp.blogspot.com/-j387Nw12NC4/UqOz_qwIwsI/AAAAAAAADWg/cmhGPbkywwA/s1600/nangis.png", ":nangis:");
  emo(/\s:imut:/g, "http://4.bp.blogspot.com/-MyN3Q5FwlzQ/UqOz8Zhmd_I/AAAAAAAADVg/MicFi01rbnw/s1600/imut.png", ":imut:");


	var one = 0; // Show alert one times!

	// Click anywhere to hide the emoticon
	$(document.body).on("click", function() {
		$('.emoKey').remove();
	});

	// Click to show the code!
	$('.emo').css('cursor', 'pointer').on("click", function(e) {
		$('.emoKey').remove();
		$(this).after('<input class="emoKey" type="text" size="5" value=" ' + this.alt + '" />');
		$('.emoKey').trigger("select");
		if(emoMessage && one === 0) {
			alert(emoMessage);
			one = 1;
		}
		e.stopPropagation();
	});

});
